﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

using ECCIT.Data;
using OgilvyOne.Sharan.Model;
using OgilvyOne.Sharan.IDAL;

namespace OgilvyOne.Sharan.DAL
{
    public class WeiboUserDAL : IDALWeiboUser
    {
        private const string C_TABLE_NAME = "tbl_KOLWeiboAccount";
        private const string C_COL_USER_ID = "col_UserID";
        private const string C_COL_LOGIN_NAME = "col_LoginName";
        private const string C_COL_PASSWORD = "col_Password";
        private const string C_COL_USER_WEIBO_ID = "col_UserWeiboID";
        private const string C_COL_AGE = "col_Age";
        private const string C_COL_JOB = "col_Job";
        private const string C_COL_HOBBY = "col_Hobby";

        private const string C_SQL_SELECT_ALL_USERS = "select " + C_COL_USER_ID + "," + C_COL_LOGIN_NAME + "," + C_COL_PASSWORD + "," + C_COL_USER_WEIBO_ID + "," + C_COL_AGE + "," + C_COL_JOB + "," + C_COL_HOBBY + " from " + C_TABLE_NAME;

        #region IDALWeiboUser 成员

        public List<WeiboUserModel> GetAllWeiboUsers()
        {
            try
            {
                List<WeiboUserModel> users = new List<WeiboUserModel>();

                using (IDataReader reader = DBHelper.ExecuteReader(C_SQL_SELECT_ALL_USERS))
                {
                    while (reader.Read())
                    {
                        int? id = (int)reader[C_COL_USER_ID];
                        string loginName = (string)reader[C_COL_LOGIN_NAME];
                        string pwd = (string)reader[C_COL_PASSWORD];
                        long? weiboUserID = (long?)reader[C_COL_USER_WEIBO_ID];
                        int? age = (int?)reader[C_COL_AGE];
                        string job = (string)reader[C_COL_JOB];
                        string hobby = (string)reader[C_COL_HOBBY];

                        users.Add(new WeiboUserModel(id, loginName, pwd, weiboUserID, age, job, hobby));
                    }
                }

                return users;
            }
            catch (Exception ex)
            {
                throw new Exception("Error occurred in WeiboUserDAL.GetAllWeiboUsers(). Message: " + ex.Message);
            }
        }

        #endregion
    }
}